//
//  CZMainTabBarController.swift
//  CZWeiBo1
//
//  Created by 1 on 15/11/22.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

class CZMainTabBarController: UITabBarController {
    func composeClick(){
      print("单机了添加按钮")
        print("****")
      
    }
 
    override func viewDidLoad() {
        super.viewDidLoad()
      //设置自定义tabbar
        let newTabbar=CZTabbar()
        //kvc设置系统的tabbar
         setValue(newTabbar, forKey: "tabBar")
//
        
        newTabbar.composeButton.addTarget(self, action: "composeClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        
      tabBar.tintColor = UIColor.orangeColor()
        
        //设置首页
        let homeVc=CZHomeTableViewController()
//        addChildViewController(UINavigationController(rootViewController: homeVc))
//        homeVc.title="首页"
//        homeVc.tabBarItem.image=UIImage(named:"tabbar_home")
//        //高亮的图片的
//        let hightlightedimageName="tabbar_home"+"_highlighted"
//        let hightlightedImage=UIImage(named: hightlightedimageName)?.imageWithRenderingMode(.AlwaysOriginal)
//        homeVc.tabBarItem.selectedImage=hightlightedImage
//        
         addChildViewController(homeVc, title: "首页", imageName: "tabbar_home")
        
        
        
        
        let messageVc=CZMessageTableViewController()
        addChildViewController(messageVc, title: "消息", imageName: "tabbar_message_center")
        
        //占位的控制器
//        addChildViewController(UIViewController())
        
        
//        addChildViewController(<#T##controller: UIViewController##UIViewController#>, title: <#T##String#>, imageName: <#T##String#>)
        
        let discoverVc=CZDiscoverTableViewController()
        addChildViewController(discoverVc, title: "发现", imageName: "tabbar_discover")
        
        
        let profileVc=CZProfileTableViewController()
        addChildViewController(profileVc, title: "我", imageName: "tabbar_profile")
   
        
    }
 
    private func addChildViewController(controller: UIViewController,title:String,imageName:String) {
        
        controller.title=title
        controller.tabBarItem.image=UIImage(named: imageName)
        let hightName=imageName+"_highlighted"
        let hightImage=UIImage(named: hightName)?.imageWithRenderingMode(.AlwaysOriginal)
        controller.tabBarItem.selectedImage=hightImage
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Highlighted)
        addChildViewController(UINavigationController(rootViewController: controller))
        
    }
    
    //下面的是有使用系统的tabar
//    //懒加载
//    lazy var composerButton:UIButton={
//        let button=UIButton()
//        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
//        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
//        //添加到tabbar里面
//       self.tabBar.addSubview(button)
//        //添加点击事件
//        button.addTarget(self, action: "composeClick", forControlEvents: UIControlEvents.TouchUpInside)
//        
//      
//        
//       return button
//    }()
//   
//   //添加按钮的单机时间的fangfa
//    func composeClick(){
//      print("单机了添加按钮")
//     
//    }
//    
//    override func viewWillAppear(animated: Bool) {
//           super.viewWillAppear(animated)
//        
//          //设置按钮的frame
//        let width=tabBar.bounds.size.width/5
//        let frame=CGRect(x: 2*width-5, y: 0, width: width+10, height: tabBar.bounds.height)
//        
//        composerButton.frame=frame
//        
//        
//    }
//    
    
    
    
}
